package heven.holt.library.extensions

import android.graphics.drawable.Drawable
import android.widget.ImageView
import com.bumptech.glide.load.MultiTransformation
import com.bumptech.glide.load.resource.bitmap.CenterCrop
import com.bumptech.glide.load.resource.bitmap.CircleCrop
import com.bumptech.glide.load.resource.bitmap.RoundedCorners
import com.bumptech.glide.request.RequestOptions
import heven.holt.library.R
import heven.holt.library.glide.GlideApp

private val avatarOptions = RequestOptions.bitmapTransform(CircleCrop())

fun ImageView.setAvatar(url: String?) {
    GlideApp.with(this).load(url).error(R.mipmap.default_avatar).apply(avatarOptions).into(this)
}

fun ImageView.setPic(url: String?) {
    GlideApp.with(this).load(url).into(this)
}

fun ImageView.setPic(drawable: Drawable?) {
    GlideApp.with(this).load(drawable).into(this)
}

fun ImageView.setPicCenterCrop(url: String?) {
    GlideApp.with(this).load(url).centerCrop().into(this)
}

fun ImageView.setPicRadius(url: String?, radius: Int) {
    val multiTransformation = MultiTransformation(CenterCrop(),RoundedCorners(radius))
    val option = RequestOptions.bitmapTransform(multiTransformation)
        .placeholder(R.drawable.shape_album_loading_bg)
    GlideApp.with(this).load(url).apply(option).into(this)
}